|
IMPACT AIT |
Return to Index
›FTP Client - VB6 - Upload Files
Using Visual Basic 6 for FTP Client
Upload vision program files to an IMPACT device using FTP
You can use this Visual Basic application (which contains a Microsoft Winsock control and a Microsoft Internet Transfer Control) to upload files from the client PC to a user-defined list of devices.
Notes:
The default AIT root distribution folder for this application is:
/Datalogic/IMPACT/AIT/FTP Client.
Any vision program files to be uploaded must not have executable permission or
spaces in the file name.
How do I change permissions?
The text file (IMPACT List.txt) must be in the same distribution subfolder
as the Visual Basic executable Upload_Programs.exe – /VisualBasic6/Example2/Project.
Create
the Visual Basic program
Create the upload
reference text file IMPACT List.txt
Upload the vision program files
Create the Visual Basic program
1.
Start
Microsoft Visual Basic 6.0. (Note: This sample code is in the AIT distribution
subfolder /VisualBasic6/Example2/Project.)
2.
Select
a new Standard EXE project type.
3.
From
the project explorer, select Project1 and press F4.
4.
Rename
the project to Upload_Programs.
5.
From
the Projects pull down menu select References.
6.
Select
Microsoft Scripting Runtime and click OK.
7.
Press
Ctrl-T to show the component selection dialog box.
8.
Select
Microsoft Internet Transfer Control 6.0.
9.
Select
Microsoft Winsock Control 6.0 and click Close.
10.
Select
the Inet control from the toolbox and place it on the form.
11.
Change
the Inet1 control’s Password property to 0197411.
12.
Change
the Inet1 control’s Protocol property to icFTP.
13.
Change
the Inet1 control’s UserName property to PptImpact (case sensitive).
14.
Select
the Microsoft Winsock control from the toolbox and place it on the form.
15.
Select
the Timer control from the toolbox, place it on the form, and change the
Interval property to 50.
16.
Add
two commandbuttons to the form.
17.
Change
Command1’s name to rescan
and the caption to Rescan Local.
18.
Change
Command2’s name to transfer
and the caption to Upload Files.
19.
Add
a Checkbox and change the name to reboot
and the caption to Reboot IMPACT Upon
Transfer Completion.
20.
Add
a listbox control to the form and change the name to deviceList.
21.
Add
a drivelistbox control to the form.
22.
Add
a DirListBox control to the form.
23.
Add
a ListBox control to the form and change the name to visionPrograms.
24.
Double
click on the form and enter the following code. (You may select and copy the
code from this page, then paste it into the form.)
Option Explicit
Dim i As Integer
Dim k As Integer
Dim filename As String
Dim LinesFromFile As String
Dim NextLine As String
Dim impactList() As String
Dim fso As New FileSystemObject, txtfile, fil As File, ts As TextStream
Private Sub Dir_List()
visionPrograms.Clear
filename = Dir(Dir1.Path & "\*.vp")
Do While filename <> ""
visionPrograms.AddItem filename
filename = Dir
Loop
End Sub
Private Sub Dir1_Change()
Call Dir_List
End Sub
Private Sub Drive1_Change()
On Error GoTo Errorhandler
Dir1.Path = Drive1.Drive
Call Dir_List
Exit Sub
Errorhandler:
MsgBox "Drive Not Ready", vbCritical, Error
Drive1.Drive = "c:\"
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
deviceList.Clear
Winsock1.Close
Winsock1.RemotePort = 23
Winsock1.RemoteHost = "192.168.0.128"
Dir1.Path = "c:\"
Call Dir_List
Set fil = fso.GetFile("IMPACT List.txt")
Set ts = fil.OpenAsTextStream(ForReading)
Do Until ts.AtEndOfStream
impactList = Split(ts.ReadLine, "|")
If impactList(0) = "true" Then
deviceList.AddItem impactList(1)
End If
Loop
End Sub
Private Sub Form_Unload(Cancel As
Integer)
Winsock1.Close
End Sub
Private Sub rescan_Click()
deviceList.Clear
Form_Load
End Sub
Private Sub transfer_Click()
transfer.Caption = "Transfering"
Me.MousePointer = vbHourglass
Dim strlocal As String
Dim strRemote As String
For i = 0 To
(deviceList.ListCount - 1)
Inet1.RemoteHost = deviceList.List(i)
If Inet1.RemoteHost <> "" Then
Inet1.Execute , "CD VisionPrograms"
Do While Inet1.StillExecuting
DoEvents
Loop
For k = 0 To (visionPrograms.ListCount - 1)
strlocal = Dir1.Path & visionPrograms.List(k)
strRemote = visionPrograms.List(k)
Inet1.Execute , "PUT """ & strlocal &
""" " & strRemote
Do While Inet1.StillExecuting
DoEvents
Loop
Next k
If reboot.Value = 1 Then
Winsock1.Close
Winsock1.RemoteHost = deviceList.List(i)
Winsock1.Connect
End If
End If
Next i
reboot.Value = 0
transfer.Caption = "Upload"
Me.MousePointer = vbDefault
End Sub
Private Sub Timer1_Timer1()
Winsock1.Close
Timer1.Enabled = False
End Sub
Private
Sub Winsock1_Connect()
Winsock1.SendData "zzz" & Chr(13)
& Chr(10)
Winsock1.SendData "reboot" &
Chr(13) & Chr(10)
Winsock1.SendData "y" & Chr(13)
& Chr(10)
Timer1.Enabled = True
End Sub
25.
Save
the project and create an exe file. What
does the program User Interface look like?
Create the upload reference text file
1.
Create
a text file in the application working directory and name it IMPACT List.txt.
2.
Open
the text file and add the following entries on each line for each vision device
you want to upload files to:
boolean|IPAddress|IMPACT Description for file reference See Example
3.
The
IP Addresses in the list file marked as True will be displayed in the
deviceList listbox control on the Visual Basic form.
Upload the vision program files
1.
Run
the Visual Basic program Upload_Programs.
2.
The
program will read the IMPACT List text file and display the IP Addresses of the
listed vision devices marked as True.
3.
In
the Directory to Upload From list, select the directory that contains the
desired vision programs.
4.
Click
Upload Files to upload the vision program files to the device.
5.
If
you want the IMPACT vision device to reboot after the files are transferred,
check the checkbox named Reboot IMPACT upon
Transfer Completion.
©2003-2013 Datalogic Automation Inc. All Rights Reserved